package com.yyfax.pay.common.aspect;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.ui.ModelMap;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import com.yyfax.pay.common.constants.PayConstants;

/**
 * 支付拦截器
 * 
 * @author buyi
 * @date 2017-05-05 18:49:08
 * @since v1.0.0
 */
public class PayWebInterceptor implements HandlerInterceptor {
	@Resource
	private PayConstants payconstants;

	@Override
	public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {

		return true;
	}

	@Override
	public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
		if (modelAndView == null || !modelAndView.hasView()) {
			return;
		}

		ModelMap modelMap = modelAndView.getModelMap();
		// 设置上下文路径
		modelMap.addAttribute(payconstants.getCtx(), request.getContextPath());
	}

	@Override
	public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
	}

}
